package inits

import (
	"class/appconfig"
	"class/glodal"
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
	"log"
)

var Ctx = context.Background()

func InitRedis() {

	data := appconfig.ConfigData.Redis
	addr := fmt.Sprintf("%s:%d", data.Host, data.Port)
	glodal.Rdb = redis.NewClient(&redis.Options{
		Addr:     addr,
		Password: data.Pass, // no password set
		DB:       0,         // use default DB
	})

	err := glodal.Rdb.Set(Ctx, "key", "value", 0).Err()
	if err != nil {
		panic(err)
	}
	log.Println("redis连接成功")

}
